package com.zt.ztyh.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zt.ztyh.dto.FundsCount;
import com.zt.ztyh.dto.FundsDto;
import com.zt.ztyh.dto.FundsUserDto;
import com.zt.ztyh.entity.User;
import com.zt.ztyh.entity.ZtyhFundsUser;
import com.zt.ztyh.service.ZtyhFundsUserService;
import com.zt.ztyh.vo.funds.FundsUserVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/ztyh/fundsUser")
public class FundsUserController {

    @Autowired
    private ZtyhFundsUserService ztyhFundsUserService;

    /**
     * 添加理财
     * @param
     * @param
     * @param
     * @return
     */

    @PostMapping("/addFunds")
    @Operation(summary = "添加理财接口")
    public boolean addFunds(@RequestBody FundsDto fundsDto){
        return this.ztyhFundsUserService.addFunds(fundsDto);
    }

    /**
     * 查询用户理财
     * @param
     * @return
     */
    @PostMapping("/findByUser")
    @Operation(summary = "查询用户的理财产品")
    public Page<FundsUserVo> findByUser(@RequestBody FundsDto fundsDto){
        return this.ztyhFundsUserService.findByUser(fundsDto);
    }

    /**
     * SELECT fid,count(uid) from ztyh_funds_user where state = 0 GROUP BY fid
     * 查询该理财产品的用户量
     * @param fundsId
     * @return
     */
    @GetMapping("/findByFunds")
    public List<FundsCount> findByFunds(Long fundsId) {
        return ztyhFundsUserService.findbyfunds(fundsId);
    }

    /**
     * 根据id查询用户金额
     * @param id
     * @return
     */
    @GetMapping("/findUserById/{id}")
    @Operation(summary = "获取用户金额")
    public ZtyhFundsUser fundsUserById(@PathVariable("id") Long id){
        return this.ztyhFundsUserService.fundsUserById(id);
    }

    /**
     * 赎回
     * @param
     * @param
     * @return
     */
    @PutMapping("/updateFunds")
    @Operation(summary = "产品赎回")
    public boolean updateFunds(@RequestBody FundsUserDto fundsUserDto){
       return this.ztyhFundsUserService.updateFunds(fundsUserDto);
    }

    @GetMapping("/findUserInfo/{uid}")
    @Operation(summary = "根据用户id查询用户信息")
    public User findUserInfo(@PathVariable("uid") Long uid){
        return this.ztyhFundsUserService.findUserInfo(uid);
    }

}
